package useTask.hbaseTask;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;

import java.io.IOException;

public class deleteHbase {
    private static Configuration conf;
    private static Connection HConn;

    private static Table table;
    private static Delete delete;

    public static void deleteAll(String tableName,String rowkey) throws IOException {
        conf = HBaseConfiguration.create();
        HConn = ConnectionFactory.createConnection(conf);
        table = HConn.getTable(TableName.valueOf(tableName));
        try {
            delete = new Delete(rowkey.getBytes());
        }finally {
            table.close();
            HConn.close();
        }
    }

    public static void delete(String tableName,String rowkey,String family,String column) throws IOException {
        conf = HBaseConfiguration.create();
        HConn = ConnectionFactory.createConnection(conf);
        table = HConn.getTable(TableName.valueOf(tableName));
        try {
            delete = new Delete(rowkey.getBytes());
            delete.addColumn(family.getBytes(),column.getBytes());
        }finally {
            table.close();
            HConn.close();
        }
    }

    public static void delete(String tableName,String rowkey,String family,String column,String time) throws IOException {
        conf = HBaseConfiguration.create();
        HConn = ConnectionFactory.createConnection(conf);
        table = HConn.getTable(TableName.valueOf(tableName));
        try {
            delete = new Delete(rowkey.getBytes());
            delete.addColumn(family.getBytes(),column.getBytes(),Long.valueOf(time));
        }finally {
            table.close();
            HConn.close();
        }
    }
}
